﻿package com.guavestudios.fcon.plugins {
	import com.guavestudios.fcon.api.IControlableConsole;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.EventDispatcher;
	
	/**
	* ...
	* @author Default
	*/
	public class SimpleEditor extends EventDispatcher implements ITextEditor,IConsolePlugin {
		
		protected var display:SimpleEditorSprite;
		
		protected var console:IControlableConsole;
		
		public function SimpleEditor() {
			
			display = new SimpleEditorSprite();
			display.addEventListener(Event.SELECT,display_close);
		}
		
		private function display_close(e:Event):void {
			console.getStage().removeChild(display);
			dispatchEvent(new Event(Event.SELECT));
		}
		
		public function setEdit(obj:Object):void
		{
			if (obj is String)
			{
				display.text = String(obj);
			}
		}
		public function getEdit():Object
		{
			return display.text;
		}
		public function show():void
		{
			console.getStage().addChild(display);
		}
		
		/* INTERFACE com.guavestudios.fcon.plugins.IConsolePlugin */
		
		public function initPlugin(c:IControlableConsole):void{
			console = c;
		}
		
		public function unloadPlugin():void{
			display = null;
		}
		
		public function get State():int{
			return 0;
		}
		
		public function get Name():String{
			return "SimpleEditor";
		}
		
		public function get Version():String{
			return "0";
		}
		
		
	}
	
}